import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {Observable} from 'rxjs';
import {HTTP_URLS} from '../config/app-http.url';
import {CommonTool} from '../common/common.tool';

@Injectable({
  providedIn: 'root'
})
export class HomeService {

  constructor(private http: HttpClient) {

  }

  /**
   * 修改密码
   */
  public updateMyAppUserPassword(req: { newPassword, password }): Observable<any> {
    return this.http.put<any>(HTTP_URLS.updateMyAppUserPassword, req);
  }

  /**
   * 获取用户信息
   */
  public getMyAppUser(): Observable<any> {
    return this.http.get<any>(HTTP_URLS.getMyAppUser);
  }

  /**
   * 获取当前用户信息
   */
  public getMyAppUserInfo() {
    return this.http.get<any>(HTTP_URLS.getMyAppUserInfo);
  }

  /**
   * 修改当前用户信息
   */
  public updateMyAppUserInfo(req) {
    return this.http.put<any>(HTTP_URLS.updateMyAppUserInfo, req);
  }

  /**
   * 获取区域集合
   */
  public getMyAppAreaList(parentNode) {
    const url = CommonTool.analysisParam(HTTP_URLS.getMyAppAreaList, {parentNode});
    return this.http.get<any>(url);
  }

  /**
   * 发送验证码
   */
  public myAppSendCaptcha(req) {
    return this.http.post<any>(HTTP_URLS.myAppSendCaptcha, req);
  }

  /**
   * 修改用户手机号
   */
  public updateMyAppUserMail(req) {
    return this.http.put<any>(HTTP_URLS.updateMyAppUserMail, req);
  }

  /**
   * 修改用户邮箱
   */
  public updateMyAppUserPhone(req) {
    return this.http.put<any>(HTTP_URLS.updateMyAppUserPhone, req);
  }

  /**
   * 注销账号
   */
  public deleteMyAppUser(captcha) {
    const url = CommonTool.analysisParam(HTTP_URLS.deleteMyAppUser, {captcha});
    return this.http.delete<any>(url);
  }
}
